package org.dousb.doupicture.interfaces.assembler;


import cn.hutool.json.JSONUtil;
import org.dousb.doupicture.domain.user.entity.Picture;
import org.dousb.doupicture.interfaces.dto.picture.PictureEditRequest;
import org.dousb.doupicture.interfaces.dto.picture.PictureUpdateRequest;
import org.springframework.beans.BeanUtils;

/**
 * PictureAssembler
 *
 * @author 豆沙包
 * @version 1.0
 * @since 2025-11-07  19:41
 */
public class PictureAssembler {

    /**
     * 封装类转对象
     *
     * @param pictureEditRequest
     * @return
     */
    public static Picture toPictureEntity(PictureEditRequest pictureEditRequest) {
        Picture picture = new Picture();
        BeanUtils.copyProperties(pictureEditRequest, picture);
        //类型不同 需要转换
        picture.setTags(JSONUtil.toJsonStr(pictureEditRequest.getTags()));
        return picture;
    }

    /**
     * 对象转封装类
     *
     * @param pictureUpdateRequest
     * @return
     */
    public static Picture toPictureEntity(PictureUpdateRequest pictureUpdateRequest) {
        Picture picture = new Picture();
        BeanUtils.copyProperties(pictureUpdateRequest, picture);
        //类型不同 需要转换
        picture.setTags(JSONUtil.toJsonStr(pictureUpdateRequest.getTags()));
        return picture;
    }

}